package com.zhentao.day06.pm;

import java.awt.*;
import java.util.Arrays;
import java.util.Locale;

public class StringTest {
  public static void main(String[] args) {

    int a = 100 ;

    // String str1 = new String();
    StringBuilder sbuilder = new StringBuilder();
    sbuilder.append(a);
    String str1 = sbuilder.toString();
    System.out.println("str1 = " + str1);


    // 想转什么类型的数据, 就通过包装类.valueOf的方法来实现。
    String str = String.valueOf(a);
    System.out.println("str = " + str);

    /*String str = "123";
    Integer i = new Integer(str);

    Integer i1 = Integer.valueOf(str);

    System.out.println("i1 = " + i1);
    System.out.println("i = " + (i instanceof Integer));*/


   /* Integer i = 100 ;
    int i1 = i.intValue();// 手动拆箱。
    int a = i ;  // 自动拆箱*/


    /*int a = 3 ;

    Number n = new Number() ;
    n.setNum(a);  // 手动装箱


    Integer ii = new Integer(a);
    Integer i = a ; // 自动装箱。  1.5之后提花的功能


    System.out.println("i = " + i);
    System.out.println("ii = " + ii);*/




    /*StringBuilder sbuilder = new StringBuilder("world");

    StringBuffer stringBuffer  = new StringBuffer("Hello World");
    // 所有的对象都是通过 toString方法实现转换为字符串的。
    String string = stringBuffer.toString(); // Object 类的 toString方法
    System.out.println("string = " + string);

    String str = "hello";

    StringBuffer s1 = new StringBuffer(str);

    System.out.println("s1 = " + s1);*/


    /*stringBuffer.insert(5,"!!!");
    System.out.println("stringBuffer = " + stringBuffer);

    stringBuffer.deleteCharAt(0);
    System.out.println("stringBuffer = " + stringBuffer);
    stringBuffer.delete(0,4);
    System.out.println("stringBuffer = " + stringBuffer);

    stringBuffer.reverse();
    System.out.println("stringBuffer = " + stringBuffer);*/

    // StringBuffer insert = stringBuffer.insert(5, " !!!");
    // System.out.println("stringBuffer == insert = " + (stringBuffer == insert));
    //
    // System.out.println("insert = " + insert);
    // System.out.println("stringBuffer = " + stringBuffer);




    /*String str = new String("hello ");

    String str1 = new String("world ");

    String concat = str.concat(str1); // new StringBuilder (字符串连接);
    System.out.println("concat = " + concat);


    StringBuffer sb = new StringBuffer();  // "";  容量 , 默认容量是16个字符, 超过16个字符, 容量自动扩容。
    sb.append(concat);
    sb.append("!!!!  !!!!!");
    System.out.println("sb = " + sb);*/

    // 5. 常用方法
    /*String str = "127.0.0.1";
    // String[] split = str.split("\\.");
    // String string = Arrays.toString(split);
    // System.out.println("string = " + string);

    String a = str.replace("0", "a");
    System.out.println("a = " + a);*/


    // 4. 转换
    /*String str1 = "asdfasdfasdf";
    char[] charArray = str1.toCharArray();
    String s = String.valueOf(charArray);
    System.out.println("s = " + s);*/



    /*byte[] bytes = str1.getBytes();
    System.out.println("bytes = " + bytes);

    String upperCase = str1.toUpperCase();
    System.out.println("upperCase = " + upperCase);

    String lowerCase = upperCase.toLowerCase();
    System.out.println("lowerCase = " + lowerCase);*/


    // 3. 截取字符串

    /*String str = "asdfasdfas";
    //
    String str1 = str.substring(4,9);

    System.out.println("str1 = " + str1);*/


    /**2. String类的常用的比较方法*/
    /*String str1 = "abc";
    String str2 = "abc";
    String str3 = new String("abc");

    // == 可以比较两个字面量的大小, 也可以比较两个引用变量的地址是否相等。
    // 字符串的 equals()是重写了Object的equals方法,除子比较两个对象以外, 它还比较两个字符串的内容是否相同。
    System.out.println("str1 == str2 = " + (str1 == str2));  // true
    System.out.println("str1 == str3 = " + (str1 == str3));  // false
    System.out.println("str1.equals(str2) = " + str1.equals(str2));  // true
    System.out.println("str1.equals(str3) = " + str1.equals(str3)); */ // true


    /* 1.初始化字符串 */
    // String name = "zs"; // 直接赋值
    // String name1 = new String() ;// 构造器赋值
    // System.out.println("name1 = " + name1); // 引用数据类型的默认值是null , String类的默认值是 ""

    /*char cs [] = new char[] {'a','e','l','l','o'};  // h+e+l+l+o  = hello
    String str1 = new String(cs);
    System.out.println("str1 = " + str1);
    *//*char c = 97 ; // a = 97  b = 98
    // -128 ~ 127
    byte b = 97 ;
    byte b1 = 'a';*//*

    byte bs [] = new byte[]{97,98,99,100};
    String str2 = new String(bs) ;
    System.out.println("str2 = " + str2); // abcd*/
  }
}
